const authService = require("../services/authService");
const { successResponse, errorResponse } = require("../utils/response");

// 获取一个用户通过id
exports.login = async (ctx) => {
  try {
    const user = await authService.authenticateUser(ctx.request.body);
    const token = await authService.generateToken(user);
    ctx.body = successResponse(token, "登录成功");
  } catch (error) {
    ctx.body = errorResponse(error);
  }
};

exports.register = async (ctx) => {
  try {
    const user = await authService.createUser(ctx.request.body);
    ctx.body = successResponse(user, " 注册成功");
  } catch (error) {
    ctx.body = errorResponse(error);
  }
};
